
$(function(){
	selectConsultationSubjectControl();
});
function selectConsultationSubjectControl(){
	var basePath = $("#basePath").val();
	// 遍历添加事件
	$.each($("input[id^=diagnosisSubjectFormControl]"),function(i,item) {
		
		$(item).keyup(function(event) {
			var currentSelectId = $(item).attr("id");
			var selectRealId = "";
			// 获取后面的id
			if (currentSelectId.indexOf("-") != -1) {
				selectRealId = currentSelectId.split("-")[1];
			}
			var searchDiv = $("#"+ selectRealId +"Div");
			var pinyinReg = /^[a-zA-Z]*$/;
			var bianhaoReg = /^[a-zA-Z]\d*.?\d*$/;
			var bianhaoReg2 = /^\d*.?\d*$/;
			var getVal = item.value;
			if (getVal&& getVal.length > 1) {
				var type = 4;
				if (pinyinReg.exec(getVal)) {
					// 拼音的时候
					type = 1;
					getVal = getVal.toUpperCase();
				} else if (bianhaoReg.exec(getVal) 
						|| bianhaoReg2.exec(getVal)) {
					// 编号时
					getVal = getVal.toUpperCase();
					type = 3;
				} else {
					// 其他情况
					type = 2;
				}
				
				if (getVal.length > 1) {
					$.post(
							basePath + '/baseinfo/queryDiagnosisSubject',
						{
							queryValueType : type,
							queryValue : getVal
						},
						function(data) {
							if (typeof (data) == "string") {
								alert(data);
								return false;
							}
							searchDiv.empty();
							xunhuanZiDian2(data,searchDiv);
							// /////////////////////////////////////下按事件

							searchDiv.addClass(
											"divscroll300 search_suggest")
									.show();
							$("#"+ selectRealId +"Id").val("");
						},
						'json');
				} else {
					$("#"+ selectRealId +"Id").val("");
					searchDiv.hide();
				}
			} else {
				$("#"+ selectRealId +"Id").val("");
				searchDiv.hide();
			}
			function xunhuanZiDian2(data, com) {
				com.empty();
				var rowNum = 1;
				for ( var index in data) {
					var Obj = data[index];
					var id = Obj.id;
					var code = Obj.code;
					var name = Obj.name;
					
					var opt = $("<div>").attr('code',code).attr('id',id).attr('name',name).text(code+"-"+name).addClass("suggest_link");
					opt.mouseover(function() {
						var divOpts = $("div[rowNum][ck='ck']");
						divOpts.attr("ck","");
						$(this).addClass("suggest_link_over")
								.attr("ck","ck");
						}).mouseout(function() {
							$("div[rowNum][ck]").removeClass("suggest_link_over");
							$(this).removeClass("suggest_link_over");
							$(this).addClass("suggest_link");
						}).click(function() {
							var zhuyaozhenduanError = new Array();
							// 获取值
							var selectDivObj = $(this);
							var code = selectDivObj
									.attr("code");
							var id = selectDivObj
							.attr("id");
							var name = selectDivObj.attr("name");
							var text = selectDivObj.text();
										
										// 赋值
							$("#"+ selectRealId +"Id").val(id);
							
							$("#diagnosisSubjectFormControl-"+ selectRealId)
									.val(text);
							$("#diagnosisSubjectFormControl-"+ selectRealId)
									.focus();
							// //////////////判断逻辑end////////////////
							
							
							// 隐藏显示层
							searchDiv.hide();
						});
					com.append(opt);
				}
			}
		});
						// ////////////////////////////编码制空---------2014-01-24
		$(item).blur(function() {
			/*var currentSelectId = $(item).attr("id");
			var selectRealId = "";
			// 获取后面的id
			if (currentSelectId.indexOf("-") != -1) {
				selectRealId = currentSelectId.split("-")[1];
			}
			var doctorId = $("#"+ selectRealId +"Id").val();
			if(doctorId == ""){
				$(item).val("");
				var searchDiv = $("#"+ selectRealId +"Div");
				searchDiv.hide();
			}*/
		});
	});
}
	// ///////////////////////////////////////////////////////////////////



